Outputting Baseline Annotation String

Hi All

I am getting pretty desperate for some help here please! Starting to not see wood for the trees.

I am simply trying to out the annotation (baseline comments) into one column in a .csv file. However, despite wrapping the string in quotes, the text goes all over the show, given the commas, and such within the text.

Does anyone have any ideas please. I need to sort this asap.

Much appreciated.
Roobroo - Tue Mar 30 11:27:56 EDT 2010

Re: Outputting Baseline Annotation String
Zetareticuli - Tue Mar 30 13:16:04 EDT 2010

If you are having trouble with the formatting of the text due to comma separation, why not try a different character? For example, you could use a string like $|* as your separating character and then when you open the file in excel, you can choose to parse the file based on that string rather than parsing based on commas or tabs.

Re: Outputting Baseline Annotation String
Mathias Mamsch - Thu Apr 01 06:36:37 EDT 2010

You need to escape the problematic characters in the string. You can use the below function for that.

Regards, Mathias
 

// This function will escape  newline (\n)  tab (\t)  and  hyphens (") 
// to export them to a tab separated string
// i.e.    Hello\n"you"\t      will become      "Hello\n""You""\t"
// This can be pasted to Excel.
 
void AddEscapedStringToBuffer (string s, Buffer b) {
    // Buffer bResult = create()
        int i
        bool needEscape = false 
        if (null s) return
        // check if we need to escape the string
        if (gListviewEscapeCharacters s) needEscape = true
        
        if ( needEscape ) {   
                b += "\""
                for i in 0:length(s)-1 do {                   
                        if ( s[i] == '\"') b += '\"'          
                        b += s[i]                       
                }     
                b += "\""
        } else { 
                // if not: just add it unescaped ...
        b += s
                return
        }
        
}
 
string escapeTabsAndNewlines (string s) {
    Buffer v = create()
    AddEscapedStringToBuffer (s, v)
    string result = stringOf v
    delete v
    return result 
}

Re: Outputting Baseline Annotation String
Mathias Mamsch - Thu Apr 01 06:38:05 EDT 2010

Mathias Mamsch - Thu Apr 01 06:36:37 EDT 2010

You need to escape the problematic characters in the string. You can use the below function for that.

Regards, Mathias
 

// This function will escape  newline (\n)  tab (\t)  and  hyphens (") 
// to export them to a tab separated string
// i.e.    Hello\n"you"\t      will become      "Hello\n""You""\t"
// This can be pasted to Excel.
 
void AddEscapedStringToBuffer (string s, Buffer b) {
    // Buffer bResult = create()
        int i
        bool needEscape = false 
        if (null s) return
        // check if we need to escape the string
        if (gListviewEscapeCharacters s) needEscape = true
        
        if ( needEscape ) {   
                b += "\""
                for i in 0:length(s)-1 do {                   
                        if ( s[i] == '\"') b += '\"'          
                        b += s[i]                       
                }     
                b += "\""
        } else { 
                // if not: just add it unescaped ...
        b += s
                return
        }
        
}
 
string escapeTabsAndNewlines (string s) {
    Buffer v = create()
    AddEscapedStringToBuffer (s, v)
    string result = stringOf v
    delete v
    return result 
}

The regular expression was missing:

Regexp gListviewEscapeCharacters = regexp "[\"\\n\\t]"

 


I used that code to export the contents of listviews to excel.

Regards, Mathias

 

Re: Outputting Baseline Annotation String
Roobroo - Thu Apr 01 08:55:22 EDT 2010

Mathias Mamsch - Thu Apr 01 06:38:05 EDT 2010

The regular expression was missing:

Regexp gListviewEscapeCharacters = regexp "[\"\\n\\t]"

 


I used that code to export the contents of listviews to excel.

Regards, Mathias

 

Hi All

Many thanks to you both for your responses and suggestions, most appreciated.

I will try them out.

Thanks again